#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "database.h"

namespace Ui {
    class MainWindow;
}

namespace acidone
{

class WorkflowBase;
class CategoryManager;
class NotificationManager;

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

public slots:
	void newTask();
	void saveDatabase();
	void newCategory();

	void newSubject();
	void manageSubjects();

	void showSettings();

private:
	void createActions();
	void createMenus();

	bool loadDatabase();
	void setUpDatabase();
	void reloadCategories();
	void reloadTasks();

	void setTaskList(Database::TaskList tasks);

	static QString databasePath();

	Task* currentTask() const;
	Category* currentCategory() const;
	Category* addOrFindCategory(const QString& name);
	Subject* addOrFindSubject(const QString& name);

    Ui::MainWindow *ui;

	QAction* m_newTaskAct;
	QAction* m_editTaskAct;
	QAction* m_doneTaskAct;
	QAction* m_removeTaskAct;
	QAction* m_newCategoryAct;
	QAction* m_removeCategoryAct;
	QAction* m_renameCategoryAct;
	QAction* m_newSubjectAct;
	QAction* m_manageSubjectsAct;
	QAction* m_showSettingsAct;
	QAction* m_exitAct;

	Database* m_database;
	bool m_databaseDirty;

	CategoryManager* m_categoryManager;
	WorkflowBase* m_workflow;
	NotificationManager* m_notificationManager;

	Subject* m_meSubject;

private slots:
	void databaseChanged();

	void editCurrentTask();
	void doneCurrentTask();
	void removeCurrentTask();

	void removeCurrentCategory();
	void renameCurrentCategory();

	void updateActions();
	void categoryChanged(int index);

	void tasksStarted(Database::TaskList tasks);
};

}

#endif // MAINWINDOW_H
